/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Objects;

import Audio.MP3;
import Engine.Engine;
import com.sun.opengl.util.GLUT;
import java.io.File;
import javax.media.opengl.GL;

/**
 *
 * @author Darkstar
 */
public class Explosion extends MovableObject {
    protected float damage;
    protected int animationDuration = 20;
    protected int animationPos = 0;
    protected MP3 xpSound;

    public Explosion(int id, Engine engine, GenericObject origin, float damage, int radius)
    {
        super(id, engine);
        File xpFile = new File("explosion.mp3");
        xpSound = new MP3(xpFile);
        new Thread(xpSound).start();

        this.pos        = origin.getPos();
        this.damage     = damage;
        this.selectable = false;
        this.r          = radius;
        this.showHealthBar = false;
        this.cullingVisible = true;
        this.modelID = 1;
    }

    @Override
    public void draw(boolean self)
    {
        if(animationPos == animationDuration)
        {
            selfDestruct();
        }
        else
            animationPos++;
        GL gl = drawable.getGL();
        GLUT glut = new GLUT();
        if (visible == true) {
            gl.glPushMatrix();
            
            if(self == false)
                gl.glTranslatef(pos.x(), pos.y(), pos.z());

            gl.glRotatef(euler_ang.x(), 0, 0, 1);   // yaw
            gl.glRotatef(euler_ang.y(), 0, 1, 0);   // pitch
            gl.glRotatef(euler_ang.z(), 1, 0, 0);   // roll


            gl.glColor4f(1.0f, 0.0f, 0.0f, 0.85f);
            glut.glutSolidSphere(r*animationPos/animationDuration, 15, 15);
            gl.glPopMatrix();

        }
    }


    @Override
    public boolean collide(GenericObject other)
    {
        if(other.getClass() != Explosion.class && other.getClass() != Laser.class)
        {
            other.decreaseHealth(damage, 1);
            this.enabled = false;
            this.collidable = false;
        }
        return false;
    }
}
